#ifndef MDEFINES_H
#define MDEFINES_H

// #include <algorithm>
// #include <charconv>
// #include <string>
// #include <string_view>
// #include <sstream>

namespace ns_yht
{

// <CR> Carriage return
#ifndef CR1
#define CR1 0x0D
#endif

// Line feed – End of sentence delimiter
#ifndef LF
#define LF 0x0A
#endif

// $ Start of sentence delimiter
#ifndef SS
#define SS 0x24
#endif

// ! Start of sentence delimiter
#ifndef SD
#define SD 0x21
#endif

// * Checksum field delimiter
#ifndef CFD
#define CFD 0x2A
#endif

// , Field delimiter
#ifndef FD
#define FD 0x2C
#endif

    enum class EBOOLEAN
    {
        Unknown = 0,
        True,
        False
    };

    enum class LEFTRIGHT
    {
        Unknown = 0,
        Left,
        Right
    };

    enum class EASTWEST
    {
        Unknown = 0,
        EAST,
        WEST
    };

    enum class NORTHSOUTH
    {
        Unknown = 0,
        North,
        South
    };

    enum class REFERENCE
    {
        ReferenceUnknown = 0,
        BottomTrackingLog,               // B
        ManuallyEntered,                 // M
        WaterReferenced,                 // W
        RadarTrackingOfFixedTarget,      // R
        PositioningSystemGroundReference // P
    };

    inline uint32_t HexValue(const std::string &hex_string) noexcept
    {
        uint32_t return_value = 0;
        //    hex_string.substr();
        //    for (const auto& c : hex_string) {
        //        ()
        //    }

        //    std::stringstream ss;
        //    ss << std::hex << hex_string;
        //    fprintf(stderr, "%s\n",  ss.str().c_str());
        long value = 0;
        sscanf(hex_string.c_str(), "%lx", &value);
        return_value = static_cast<uint32_t>(value);
        // std::from_chars(&hex_string[0], &hex_string[0] + hex_string.length(), return_value, 16);
        return return_value;
    }

    // RSD
    enum class DISPLAYROTATION
    {
        RotationUnknown = 0,
        CourseUpRotation, // course-up, course-over-ground up, degrees true;
        HeadUpRotation,   // head-up, ship's heading (centre-line) 0° up;
        NorthUpRotation   // north-up, true north is 0° up.
    };

    // TTM
    enum class Degrees
    {
        DegreesUnknown = 0,
        DegreesTrue,    // T
        DegreesRelative // R
    };

    enum class SpeedOrDistanceUnits
    {
        Unknown = 0,
        K,
        N,
        S
    };

    enum class TARGET_STATUS
    {
        TargetUnknown = 0,
        TargetLost,    // L = Lost, tracked target has been lost;
        TargetQuery,   // Q = Query, target in the process of acquisition;
        TargetTracking // T = Tracking.
    };

    enum class TypeOfAcquisition
    {
        Unknown = 0,
        Automatic, // A
        Manual,    // M
        Reported   // R
    };

    // TTD
    enum class RADAR_OR_AIS_TARGET_STATUS
    {
        Unknown = 0,
        Non_Tracking_OR_No_target_to_report,                                                             // 000
        Acquiring_target_OR_Sleeping_target,                                                             // 001
        Lost_target,                                                                                     // 010
        Reserved,                                                                                        // 011
        Established_tracking_no_alarm_OR_Activated_target_no_alarm,                                      // 100
        Reserved2,                                                                                       // 101
        Established_tracking_CPA_TCPA_alarm_OR_Activated_target_CPA_TCPA_alarm,                          // 110
        Established_tracking_acknowledged_CPA_TCPA_alarm_OR_Activated_target_acknowledged_CPA_TCPA_alarm // 111
    };

    enum class OperationMode
    {
        Unknown = 0,
        Autonomous, // 0
        Test_target // 1
    };

    enum class SpeedMode
    {
        Unknown = 0,
        True,    // 0
        Relative // 1
    };

    enum class StabilisationMode
    {
        Unknown = 0,
        OverTheGround,   // 0
        ThroughTheWater, // 1
    };

    // ALR
    enum class AlarmAcknowledgeState
    {
        Unknown = 0,
        Acknownledge,  // A
        Unacknowledged // V
    };

    enum class AlarmCondition
    {
        Unknown = 0,
        ThresholdExceeded, // A
        NotExceeded        // V
    };

    // rmb
    enum class Status
    {
        Unknown = 0,
        DataVaild,         // A
        NavigationReceWarn // V
    };

    enum class ModeIndicator
    {
        Unknown = 0,
        AutoMode,           // A
        DifferentialMode,   // D
        EstimatedInputMode, // E
        ManualInputMode,    // M
        SimulatorMode,      // S
        DataNotValid,       // N

        FloatRTK,        // F
        Precise,         // P
        RealTimeKinemati // R
    };

    enum class ArrivalStatus
    {
        Unknown = 0,
        ArrivalCircle, // A
        NotEntered     // V
    };

    enum class NavigationalStatus
    {
        Unknown = 0,
        Safe,    // S
        Caution, // C
        Unsafe,  // U
        NotVaild // V
    };

    enum class VTGDegrees
    {
        DegreesUnknown = 0,
        DegreesTrue,    // T
        DegreesMagnetic // M
    };

    enum class Localdatum
    {
        Unknown = 0,
        WGS84,      // W84
        WGS72,      // W72
        SGS85,      // S85
        PE90,       // P90
        UserDefined // 999
    };

    enum class GllStatus
    {
        Unknown = 0,
        DataVaild,  // A
        DataInvaild // V
    };

    enum class ApbStatus1
    {
        Unknown = 0,
        DataVaild,  // A
        LORANCblink // V
    };

    enum class ApbStatus2
    {
        Unknown = 0,
        DataVaild,  // A
        LORANCcycle // V
    };

    enum class ApbStatus3
    {
        Unknown = 0,
        ArrivalCircle,   // A
        NotArrivalCircle // V
    };

    enum class ApbStatus4
    {
        Unknown = 0,
        PerpendicularPassed,    // A
        PerpendicularNotEntered // V
    };

    enum class AISChannel
    {
        Unknown = 0,
        A, // A
        B  // B
    };

    // 转发指示符
    enum class ForwardIndicator
    {
        Unknown,
        Default,        // 0
        NoLongerForward // 3   不再转发
    };

    enum class NavigationalState
    {
        EngineInUse = 0,
        Anchorage,
        Unmaneuverable,
        LimitedSeaworthiness,
        EatenByShipWater,
        Mooring,
        Grounding,
        Fishing,
        Sailing,

        Aissart = 14,
        Default,
        Unknown
    };

    enum class ManeuverType
    {
        Default = 0,
        NoSpecificManipulation,
        SpecificManipulation
    };

    enum class RaimFlag
    {
        Default = 0,
        RAIMUseing,
    };

    enum class AISVersion
    {
        RM13711 = 0, // 0
        RM13713,     // 1
        Unknown
    };

    enum class ElectronicDeviceTheType
    {
        Defalut = 0,     // 0
        GPS,             // 1
        GLONASS,         // 2
        GPSAndGLONASS,   // 3
        LoranC,          // 4
        Chayka,          // 5
        IntegrateSystem, // 6
        Researching,     // 7
        Galileo,         // 8
        GNSSIn           // 15
    };

    enum class DTEState
    {
        Available = 0, // 0
        Default,       // 1 不可以
    };

    enum class TalkType
    {
        TT_AG,
        TT_AP,
        TT_AI, // AIS
        TT_BD, // 北斗
        TT_CC,
        TT_CD,
        TT_CM,
        TT_CS,
        TT_CT,
        TT_CV,
        TT_CX,
        TT_DE,
        TT_DF,
        TT_EC,
        TT_EP,
        TT_ER,
        TT_GP, // GPS
        TT_GN, // GPS
        TT_HC, // 罗经
        TT_HE,
        TT_HN,
        TT_II,
        TT_IN,
        TT_LA,
        TT_LC,
        TT_MP,
        TT_OM,
        TT_OS,
        TT_PA, // 姿态仪
        TT_RA, // 雷达
        TT_SD, // 测深仪
        TT_SN,
        TT_SS,
        TT_TI,
        TT_TR,
        TT_VD,
        TT_VM,
        TT_VW,
        TT_WI, // 风速风向仪
        TT_YC,
        TT_YD,
        TT_YF,
        TT_YL,
        TT_YP,
        TT_YR,
        TT_YT,
        TT_YV,
        TT_YX,
        TT_ZA,
        TT_ZC,
        TT_ZQ,
        TT_ZV,
        TT_Other
    };

    enum class NMEAType
    {
        NT_VDM,
        NT_VDO,
        NT_ZDA,
        NT_GGA,
        NT_Other
    };

} // namespace ns_yht
#endif // MDEFINES_H
